/**
 * Created by ebalmes Oct 8, 2009 5:58:44 PM
 * 
 */
package gui.validators;

import gui.components.XField;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DateValidator implements IValidator
{


  @Override
  public boolean validate(Object o) {
    XField field = (XField)o;
    try {
      DateFormat df =new SimpleDateFormat("yyyy-MM-dd");
        
      df.setLenient(false);   // this is important!
      df.parse(field.getText());
     }
     catch (ParseException e) {
      field.setToolTipText("The correct dateformat is : 'yyyy-MM-dd'");
       return false;
     }
     catch (IllegalArgumentException e) {
       field.setToolTipText("The correct dateformat is : 'yyyy-MM-dd'");
      return false;
     }
     field.setToolTipText("");
     return true;
  }
}
